package com.kele.demo;

import com.kele.demo.config.EnvironmentModule;
import com.kele.demo.utils.BeanUtil;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author chunhui.li
 * @date 2022/2/11 10:42
 * @Description
 * @ClassName ProviderDemoApplication
 */
@SpringBootApplication
@MapperScan("com.kele.demo.mapper")
@EnableFeignClients
public class ProviderDemoApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(ProviderDemoApplication.class, args);
//        Environment environment = context.getBean(Environment.class);
        BeanUtil.applicationContext = context;
        System.out.println(context.getBean(EnvironmentModule.class));
//        getEnv(environment);
//        System.out.println(environment.getProperty("server.port") + " ==>名字 " + environment.getProperty("spring.application.name"));
//        Arrays.stream(context.getBeanDefinitionNames()).forEach(System.out::println);
    }

//    @Bean(name = "serviceEnv")
//    public static EnvironmentModule getEnv(Environment environment) {
//        EnvironmentModule environmentModule = new EnvironmentModule();
//        environmentModule.setPort(environment.getProperty("server.port"));
//        environmentModule.setServiceId(environment.getProperty("spring.application.name"));
//        return environmentModule;
//    }
}
